/*
*	create by  jack ,20210705
*	
*	描述 ：linux 中叫线程，ucos 中叫task。 
*		  该文件提供了一套线程调用的接口，屏蔽具体实现细节,以达到应用程序可以在不同的平台上联合调试。
*   修改记录：[内容][作者][时间]
*	
*/
#ifndef _TASK_MANAGER_H_
#define _TASK_MANAGER_H_

#include "define_comm.h"
#include "task_data.h"


#define KY_TASK_NAME_LEN 32

typedef sj_void  (*sj_task_init_func)(sj_void);
typedef sj_void  (*sj_task_run_func)(sj_void *arg);
typedef sj_void  (*sj_task_exit_func)(sj_void);

typedef unsigned long int sj_task_handle;

typedef  enum
{
    TASK_STATUS_NOINIT=0,
    TASK_STATUS_TIMEOUT=1,
    TASK_STATUS_EVENT=2,
    TASK_STATUS_RUNNING=3,
    TASK_STATUS_SUSPEDN=4,
    TASK_STATUS_BLOCK=5,
    TASK_STATUS_EXIT=6,
}task_status_e;


struct sj_task_t
{
    sj_task_handle  taskid;
    sj_char *name;
    sj_task_run_func  run_func;
    sj_task_init_func init_func;
    sj_task_exit_func exit_func;
    struct sj_task_data *task_data;
};


/**
 * @brief  task create . if periodtime > 0 , the task will run in  period
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_create(struct sj_task_t *task);

/**
 * @brief  task destory .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_destory(struct sj_task_t *task);

/**
 * @brief  sun the task one time .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_run_onetime(struct sj_task_t *task);

/**
 * @brief  resume the task .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_resume(struct sj_task_t *task,sj_int32 periodtime);

/**
 * @brief  suspend the task .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_suspend(struct sj_task_t *task);

/**
 * @brief  get the task current state.
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_task_get_current_state(struct sj_task_t *task);








/**
 * @brief  sem create .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_sem_create(sj_sem* sem ,sj_int8 v);

/**
 * @brief  sem create .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_sem_destory(sj_sem* sem);

/**
 * @brief wait sem .
 * @return 1  timeout
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_sem_wait(sj_sem* sem,sj_int32 timeout);


/**
 * @brief  sem post .
 * @return 0  success.
 * @return <-1 fail.
 */
sj_int8 sj_sem_post(sj_sem* sem);

#endif
